<% layout("/layouts/micro.html",{title:"内容发布管理"}){ %>
<div class="childrenBody">
	<div class="kit-table">
		<form class="layui-form" lay-filter="kit-search-form">
			<div class="kit-table-header">
				<div class="kit-search-btns">
					<%if(shiro.hasPermission("cms:article:edit")){%>
					<a class="layui-btn layui-btn-normal addarticle_btn"><i class="layui-icon">&#xe608;</i>新增</a>
					<%}%>
					<div class="layui-input-inline">
						<label class="layui-form-label">状态：</label>
						<div class="layui-input-inline">
							<#radio name="delFlag" items="${@DictUtils.getDictList('cms_del_flag')}"  value="${article.delFlag}"/>
						</div>
					</div>
				</div>
				<div class="kit-search-inputs clearfix">
					<div class="kit-search-keyword">
						<input type="text" class="layui-input" id="keyword" name="keyword" placeholder="标题" />
						<button class="search_btn" type="button"><i class="layui-icon">&#xe615;</i></button>
					</div>
				</div>
			</div>
		</form>
		<div class="kit-table-body">
			<table id="articleList" lay-filter="articleList"></table>
			<!--操作-->
			<script type="text/html" id="articleListBar">
				<a class="layui-btn layui-btn-xs" href="${ctxFront}/view-${article.category.id}-{{d.id}}${@Global.getUrlSuffix()}" target="_blank">访问</a>
				<%if(shiro.hasPermission("cms:article:edit")){%>
				<%if(article.category.allowComment == '1'){%>
				<%if(shiro.hasPermission("cms:comment:view")){%>
				<a class="layui-btn layui-btn-xs" href="${ctx}/cms/comment/?module=article&contentId={{d.id}}&delFlag=2" onclick="return viewComment(this.href);">评论</a>
				<%}%>
				<%}%>
				<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
				<%if(shiro.hasPermission("cms:article:audit")){%>
				{{#  if(d.delFlagValue == "0"){ }}
				<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
				{{#  } else{    }}
				<a class="layui-btn layui-btn-xs" lay-event="release">发布</a>
				{{#  }}}

				<%}%>
				<%}%>
			</script>
		</div>

	</div>
</div>

<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //列表
        var tableIns = table.render({
            elem: '#articleList',
            url : '${ctx}/cms/article/listAjax?categoryId=${article.category.id!}',
            cellMinWidth : 95,
            page : true,
            request: {
                pageName: 'pageNo', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            height : "full-70",
            limit : 15,
            limits : [10,15,20,25],
            id : "articleListTable",
            cols : [[
                /* {type: "checkbox", fixed:"left", width:50}, */
                {field:'categoryName', title: '栏目'},
                {field:'title',title: '标题'},
                {field:'weight', title: '权重'},
                {field:'hits', title: '点击数'},
                {field:'userName',title: '发布者'},
                {field:'updateDate', title: '更新时间'},
                {title: '操作', width:200, templet:'#articleListBar',fixed:"right",align:"center"}

            ]],
        });

        //搜索
        $(".search_btn").on("click",function(){
            var keyword = $('#keyword');
            var delFlag = $('input[name=delFlag]:checked');
            /* var categoryId = $('#categoryId'); */
            table.reload("articleListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    keyword : keyword.val(),
                    delFlag : delFlag.val(),
                    /* categoryId : categoryId.val(), */
                }
            })
        });

        form.render(null, 'kit-search-form');
        $('#kit-search-more').on('click', function() {
            $('.kit-search-mored').toggle();
        });
        //添加
        function addarticle(id){
            var index = layui.layer.open({
                    title : "添加文章",
                    type : 2,
                    maxmin:true,
                    content : "${ctx}/cms/article/form?id="+id+"&${article.id}&category.id=${article.category.id}&category.name=${article.category.name}",
                    area: ['90%', '90%'],
                <%if(shiro.hasPermission("cms:article:edit")){%>
                btn: ['保存', '取消'],
                    yes: function(index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法;
                    iframeWin.saveForm();
                }
            <%}%>
        })
        }
        $(".addarticle_btn").click(function(){
            var id = '${article.id}';
            addarticle(id);
        })
        //列表操作
        table.on('tool(articleList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'edit'){ //编辑
                addarticle(data.id);
            } else if(layEvent === 'release'){ //发布
                layer.confirm('确认要发布该文章吗？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/cms/article/delete",{id:data.id,isRe:true},function(result){
                        if(result.code=="0"){
                            layer.msg(result.msg);
                        }else{
                            layer.msg(result.msg);
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });
            } else if(layEvent === 'del'){
                layer.confirm('确认要删除该文章吗？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/cms/article/delete",{id:data.id},function(result){
                        if(result.code=="0"){
                            layer.msg(result.msg);
                        }else{
                            layer.msg(result.msg);
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });

            }
        });

    })
    function viewComment(href){

        layer.open({
            type: 2,
            title: "查看评论",
            shadeClose: true,
            shade: 0.3,
            area: ['900px','550px'],
            content: href,
            btn: ['关闭'],
            yes: function(index, layero){
                layer.close(index);
            }
        });
        return false;
    }

</script>
<%}%>